﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeiBoUI.Helper;
using System.Drawing;

namespace WeiBoUI.ToolstripEx
{
    public class LeftMainStripRenderer : ToolStripRenderer
    {
        private int i;
        public Bitmap _main_tabbtn = ImageHelper.GetResBitmap("ToolStripImg.tab.bmp");
        public LeftMainStripRenderer()
        {
        }

        protected override void InitializeItem(ToolStripItem item)
        {
            base.InitializeItem(item);
            item.AutoSize = false;
            item.Height = 30;
            item.Padding = new Padding(5);
            item.Margin = new Padding(0, 0, 0, 1);
            if (item is ToolStripButton)
            {
                ToolStripButton btn = item as ToolStripButton;
                btn.Click += new EventHandler(btn_Click);
                item.Width = 40;
            }

        }

        void btn_Click(object sender, EventArgs e)
        {
            ToolStripButton btn = sender as ToolStripButton;
            btn.Checked = true;
        }

        #region 绘制 ToolStripButton 的背景。
        protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        {
            bool chk = false;
            chk = (e.Item as ToolStripButton).Checked;
            if (e.Item.Pressed && e.Item.Selected)
            {
                i = 2;
            }
            else if (e.Item.Selected)
            {
                i = 1;
            }
            else if (chk)
            {
                i = 2;
            }
            else
            { i = 0; }
            ImageHelper.DrawRect(e.Graphics, _main_tabbtn,
                new Rectangle(Point.Empty, e.Item.Size), Rectangle.FromLTRB(5, 15, 5, 5), i, 2);
        }
        #endregion

    }
}
